﻿using System;
using FS.Business;
using System.Data;
using System.Text;
using System.Collections;
using FS.Common.DotNetUI;
using FS.Web.BLL.Query;

namespace FS.Web.BLL.Report
{
    public partial class Report_VisaInfo : System.Web.UI.Page
    {
        private visa_dao _visa = new visa_dao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                initBase_CertType();
                GetSelect_TrustInfo();
                GetSelect_InfoFlag();
                GetSelect_CityInfo();
                GetSelect_SupplyInfo();
                initBase_moneyflag();
                initBase_moneytype();

                this.begdate.Value = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
                this.enddate.Value = DateTime.Now.ToString("yyyy-MM-dd");
                this.databind(null);
            }
        }


        #region 下拉菜单
        //签证类型
        private void initBase_CertType()
        {
            DataTable dt = _visa.GetSelect_CertType();
            ControlBindHelper.BindHtmlSelect(dt, this.Ref_CertType, "property_value", "property_id", "请选择");
        }

        //委托方
        private void GetSelect_TrustInfo()
        {
            DataTable dt = _visa.GetSelect_TrustInfo();
            ControlBindHelper.BindHtmlSelect(dt, this.trust_id, "name", "trust_id", "请选择");
        }

        //签证国家
        private void GetSelect_CityInfo()
        {
            DataTable dt = _visa.GetSelect_CityInfo();
            ControlBindHelper.BindHtmlSelect(dt, this.cityid, "City_name", "City_id", "请选择");
        }

        //签证状态
        private void GetSelect_InfoFlag()
        {
            DataTable dt = _visa.GetSelect_InfoFlag();
            ControlBindHelper.BindHtmlSelect(dt, this.InfoFlag, "property_value", "property_id", "请选择");
        }

        //供应商信息
        private void GetSelect_SupplyInfo()
        {
            DataTable dt = _visa.GetSelect_SupplyInfo();
            ControlBindHelper.BindHtmlSelect(dt, this.supplyid, "Supply_Name", "Supply_id", "请选择");
        }

        //收款方式
        private void initBase_moneytype()
        {
            DataTable dt = _visa.GetSelect_moneytype();
            ControlBindHelper.BindHtmlSelect(dt, this.moneytype, "property_value", "property_id", "请选择");

        }

        //收款情况
        private void initBase_moneyflag()
        {
            DataTable dt = _visa.GetSelect_moneyflag();
            ControlBindHelper.BindHtmlSelect(dt, this.moneyflag, "property_value", "property_id", "请选择");
        }

        #endregion

        private void DataBindGrid()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select m.info_no,trust.trust_name,convert(varchar(10),m.info_getdate,120) as info_getdate, ");
            sb.Append(" city.city_name,certtype.property_value as CertType,supply.supply_name,");
            sb.Append(" infoflag.property_value as infoflag,moneytype.property_value as moneytype,");
            sb.Append(" moneyflag.property_value as moneyflag,m.info_moneyin,m.info_moneyout,");
            sb.Append(" d.InfoDetail_user,d.InfoDetail_cardno");
            sb.Append(" from Visa_Info m ");
            sb.Append(" inner join Visa_InfoDetail d on m.info_id = d.info_id");
            sb.Append(" inner join base_trust trust on m.trust_id = trust.trust_id ");
            sb.Append(" inner join base_city city on city.city_id=d.city_id ");
            sb.Append(" inner join sys_parm infoflag on infoflag.property_id=m.ref_infoflag ");
            sb.Append(" left join base_supply supply on supply.supply_id=d.supply_id ");
            sb.Append(" inner join sys_parm certtype on certtype.property_id=d.Ref_CertType ");
            sb.Append(" inner join sys_parm moneytype on moneytype.property_id=m.Ref_moneytype ");
            sb.Append(" inner join sys_parm moneyflag on moneyflag.property_id=m.Ref_moneyflag ");
            sb.Append(" where m.deletemark=1 and d.deletemark=1 ");

            string ls_trust = this.trust_id.Value;
            if (!string.IsNullOrEmpty(ls_trust))
            {
                sb.Append(string.Format(" and m.trust_id='{0}'", ls_trust));
            }

            string ls_begdate = this.begdate.Value;
            string ls_enddate = this.enddate.Value;
            sb.Append(string.Format(" and m.info_getdate>='{0}'", ls_begdate));
            sb.Append(string.Format(" and m.info_getdate<='{0}'", ls_enddate));

            string ls_city = this.cityid.Value;
            if (!string.IsNullOrEmpty(ls_city))
            {
                sb.Append(string.Format(" and d.City_id='{0}'", ls_city));
            }

            string ls_certtype = this.Ref_CertType.Value;
            if (!string.IsNullOrEmpty(ls_certtype))
            {
                sb.Append(string.Format(" and d.Ref_CertType='{0}'", ls_certtype));
            }

            string ls_supply = this.supplyid.Value;
            if (!string.IsNullOrEmpty(ls_supply))
            {
                sb.Append(string.Format(" and d.Supply_id='{0}'", ls_supply));
            }

            string ls_infoflag = this.InfoFlag.Value;
            if (!string.IsNullOrEmpty(ls_infoflag))
            {
                sb.Append(string.Format(" and m.Ref_infoflag='{0}'", ls_infoflag));
            }

            string ls_moneytype = this.moneytype.Value;
            if (!string.IsNullOrEmpty(ls_moneytype))
            {
                sb.Append(string.Format(" and m.Ref_moneytype='{0}'", ls_moneytype));
            }

            string ls_moneyflag = this.moneyflag.Value;
            if (!string.IsNullOrEmpty(ls_moneyflag))
            {
                sb.Append(string.Format(" and m.Ref_moneyflag='{0}'", ls_moneyflag));
            }

            string ls_user = this.InfoDetail_user.Value;
            if (!string.IsNullOrEmpty(ls_user))
            {
                sb.Append(string.Format(" and d.InfoDetail_user='{0}'", ls_user));
            }

            string ls_card = this.InfoDetail_cardno.Value;
            if (!string.IsNullOrEmpty(ls_card))
            {
                sb.Append(string.Format(" and d.InfoDetail_cardno='{0}'", ls_card));
            }

            DataTable dt = DataFactory.Run().GetDataTableBySQL(sb);
            //ControlBindHelper.BindRepeaterList(dt, this.rp_Item);
        }

        protected void lbtSearch_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            Hashtable ht = new Hashtable();
            ht.Add("begdate", this.begdate.Value);
            ht.Add("enddate", this.enddate.Value);
            ht.Add("country", this.cityid.Value);
            ht.Add("certtype", this.Ref_CertType.Value);
            ht.Add("supply", this.supplyid.Value);
            ht.Add("customer", this.trust_id.Value);
            ht.Add("infoflag", this.InfoFlag.Value);
            ht.Add("moneytype", this.moneytype.Value);
            ht.Add("user", this.InfoDetail_user.Value);
            ht.Add("usercard", this.InfoDetail_cardno.Value);
            DataTable dt = DataFactory.Run().GetDataTableProc("usp_Report_Visainfo", ht);

            this.databind(dt);
        }

        private void databind(DataTable dt)
        {
            if (dt == null)
            {
                dt = new ds_report().usp_Report_Visainfo;
                dt.NewRow();
            }
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
        }
    }
}